package com.balance.anole.erp.component;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ViewerCell;

public abstract class AbstractEditingSupport extends ObservableValueEditingSupport {

	protected CellEditor cellEditor;

	protected String propertyName;

	public AbstractEditingSupport(ColumnViewer viewer, DataBindingContext dbc) {
		super(viewer, dbc);
	}

	public AbstractEditingSupport(ColumnViewer viewer, DataBindingContext dbc, String propertyName) {
		this(viewer, dbc);
		this.propertyName = propertyName;
	}

	@Override
	protected IObservableValue doCreateElementObservable(Object element,
			ViewerCell cell) {
		return BeansObservables.observeValue(element, propertyName);
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return cellEditor;
	}

}
